package com.qiyi.player.wonder.plugins.scenetile.view
{
   import org.puremvc.as3.patterns.mediator.Mediator;
   import com.qiyi.player.wonder.plugins.scenetile.model.SceneTileProxy;
   import com.qiyi.player.wonder.plugins.scenetile.SceneTileDef;
   import com.qiyi.player.wonder.body.BodyDef;
   import com.qiyi.player.wonder.plugins.continueplay.ContinuePlayDef;
   import org.puremvc.as3.interfaces.INotification;
   import com.qiyi.player.wonder.body.model.JavascriptAPIProxy;
   import com.iqiyi.components.global.GlobalStage;
   import com.qiyi.player.wonder.body.model.PlayerProxy;
   import com.qiyi.player.wonder.body.model.UserProxy;
   import com.qiyi.player.wonder.common.vo.UserInfoVO;
   
   public class SceneTileFocusViewMediator extends Mediator
   {
      
      public function SceneTileFocusViewMediator(param1:SceneTileFocusView) {
         super(NAME,param1);
         this._sceneTileFocusView = param1;
      }
      
      public static const NAME:String = "com.qiyi.player.wonder.plugins.scenetile.view.SceneTileFocusViewMediator";
      
      private var _sceneTileProxy:SceneTileProxy;
      
      private var _sceneTileFocusView:SceneTileFocusView;
      
      override public function onRegister() : void {
         super.onRegister();
         this._sceneTileProxy = facade.retrieveProxy(SceneTileProxy.NAME) as SceneTileProxy;
         this._sceneTileFocusView.addEventListener(SceneTileEvent.Evt_FocusOpen,this.onFocusViewOpen);
         this._sceneTileFocusView.addEventListener(SceneTileEvent.Evt_FocusClose,this.onFocusViewClose);
         this._sceneTileFocusView.addEventListener(SceneTileEvent.Evt_FocusBtnClick,this.onFocusBtnClick);
      }
      
      override public function listNotificationInterests() : Array {
         return [SceneTileDef.NOTIFIC_ADD_STATUS,SceneTileDef.NOTIFIC_REMOVE_STATUS,BodyDef.NOTIFIC_PLAYER_REPLAYED,BodyDef.NOTIFIC_RESIZE,BodyDef.NOTIFIC_CHECK_USER_COMPLETE,BodyDef.NOTIFIC_PLAYER_ADD_STATUS,BodyDef.NOTIFIC_PLAYER_SWITCH_PRE_ACTOR,BodyDef.NOTIFIC_JS_CALL_SET_FOCUS_RESULT,ContinuePlayDef.NOTIFIC_ADD_STATUS];
      }
      
      override public function handleNotification(param1:INotification) : void {
         super.handleNotification(param1);
         var _loc2_:Object = param1.getBody();
         var _loc3_:String = param1.getName();
         var _loc4_:String = param1.getType();
         switch(_loc3_)
         {
            case SceneTileDef.NOTIFIC_ADD_STATUS:
               if(int(_loc2_) == SceneTileDef.STATUS_FOCUS_OPEN)
               {
                  this._sceneTileFocusView.focusInfo = this._sceneTileProxy.focusInfo;
               }
               this._sceneTileFocusView.onAddStatus(int(_loc2_));
               break;
            case SceneTileDef.NOTIFIC_REMOVE_STATUS:
               this._sceneTileFocusView.onRemoveStatus(int(_loc2_));
               break;
            case BodyDef.NOTIFIC_RESIZE:
               this._sceneTileFocusView.onResize(_loc2_.w,_loc2_.h);
               break;
            case BodyDef.NOTIFIC_CHECK_USER_COMPLETE:
               this.onCheckUserComplete();
               break;
            case BodyDef.NOTIFIC_PLAYER_ADD_STATUS:
               this.onPlayerStatusChanged(int(_loc2_),true,_loc4_);
               break;
            case BodyDef.NOTIFIC_PLAYER_SWITCH_PRE_ACTOR:
               this.onPlayerSwitchPreActor();
               break;
            case BodyDef.NOTIFIC_PLAYER_REPLAYED:
               this._sceneTileProxy.isAlreadyShowFocus = false;
               break;
            case BodyDef.NOTIFIC_JS_CALL_SET_FOCUS_RESULT:
               if(int(_loc2_) == 1 && !(this._sceneTileProxy.focusInfo == null) && !this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_FOCUS_OPEN))
               {
                  this._sceneTileProxy.addStatus(SceneTileDef.STATUS_FOCUS_OPEN);
               }
               this._sceneTileFocusView.setFocusResult(int(_loc2_) == 0?false:true);
               break;
            case ContinuePlayDef.NOTIFIC_ADD_STATUS:
               if(int(_loc2_) == ContinuePlayDef.STATUS_OPEN)
               {
                  this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_FOCUS_OPEN);
               }
               break;
         }
      }
      
      private function onFocusViewOpen(param1:SceneTileEvent) : void {
         if(!this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_FOCUS_OPEN))
         {
            this._sceneTileProxy.addStatus(SceneTileDef.STATUS_FOCUS_OPEN);
         }
      }
      
      private function onFocusViewClose(param1:SceneTileEvent) : void {
         if(this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_FOCUS_OPEN))
         {
            this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_FOCUS_OPEN);
         }
      }
      
      private function onFocusBtnClick(param1:SceneTileEvent) : void {
         var _loc2_:JavascriptAPIProxy = facade.retrieveProxy(JavascriptAPIProxy.NAME) as JavascriptAPIProxy;
         _loc2_.callJSFocusUploader();
         GlobalStage.setNormalScreen();
      }
      
      private function onPlayerStatusChanged(param1:int, param2:Boolean, param3:String) : void {
         if(param3 != BodyDef.PLAYER_ACTOR_NOTIFIC_TYPE_CUR)
         {
            return;
         }
         var _loc4_:PlayerProxy = null;
         switch(param1)
         {
            case BodyDef.PLAYER_STATUS_ALREADY_LOAD_MOVIE:
               if(param2)
               {
                  if(this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_FOCUS_OPEN))
                  {
                     this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_FOCUS_OPEN);
                  }
                  this._sceneTileProxy.isAlreadyShowFocus = false;
                  this._sceneTileProxy.focusInfo = null;
               }
               break;
         }
      }
      
      private function onPlayerSwitchPreActor() : void {
         if(this._sceneTileProxy.hasStatus(SceneTileDef.STATUS_FOCUS_OPEN))
         {
            this._sceneTileProxy.removeStatus(SceneTileDef.STATUS_FOCUS_OPEN);
         }
         this._sceneTileProxy.isAlreadyShowFocus = false;
         this._sceneTileProxy.focusInfo = null;
      }
      
      private function onCheckUserComplete() : void {
         var _loc1_:UserProxy = facade.retrieveProxy(UserProxy.NAME) as UserProxy;
         var _loc2_:UserInfoVO = new UserInfoVO();
         _loc2_.isLogin = _loc1_.isLogin;
         _loc2_.passportID = _loc1_.passportID;
         _loc2_.userName = _loc1_.userName;
         _loc2_.userLevel = _loc1_.userLevel;
         this._sceneTileFocusView.onUserInfoChanged(_loc2_);
      }
   }
}
